package com.linhui.project.datasource;

import com.linhui.project.model.enums.SearchTypeEnum;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: 临晖
 * @since: 2024-05-19
 */

@Component
public class DataRegister {

    @Resource
    private  PictureDataSource pictureDataSource;

    @Resource
    private  UserDataSource userDataSource;

    @Resource
    private  PostDataSource postDataSource;

    private  Map<String, DataSource> map;

    @PostConstruct
    public void doInit() {
        map = new HashMap() {
            {
                put(SearchTypeEnum.getTypeEnumOnValue("post").getValue(), postDataSource);
                put(SearchTypeEnum.getTypeEnumOnValue("picture").getValue(), pictureDataSource);
                put(SearchTypeEnum.getTypeEnumOnValue("user").getValue(), userDataSource);

            }
        };
    }


    public  void register(String key, DataSource value) {
        map.put(key, value);
    }

    public  DataSource getDataSource(String key) {
        if (map.containsKey(key)) {
            return map.get(key);
        }

        return null;
    }
}
